package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.User;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 * @author zuosy
 * @created 2024/4/3 11:13
 */
public record UserDTO(
        @Schema(description = "ID")
        @NotNull(message = "id不能为空")
        Long id,

        @Schema(description = "用户名")
        @NotBlank(message = "用户名不能为空")
        String username,

        @Schema(description = "角色")
        @NotBlank(message = "角色不能为空")
        String role,

        @Schema(description = "性别")
        @NotBlank(message = "性别不能为空")
        String gender,

        @Schema(description = "邮箱")
        @NotBlank(message = "邮箱不能为空")
        @Email(message = "邮箱格式不正确")
        String email,

        @Schema(description = "简介")
        String introduction
) {

    /**
     * 修改用户的DTO转实体类
     *
     * @param userDTO
     * @return
     */
    public static User convertDTO(UserDTO userDTO) {
        return new User(userDTO.id, userDTO.username, userDTO.role, userDTO.email, userDTO.gender, userDTO.introduction);
    }
}
